package cn.dnui_wnx725.dnuifood_16110100725.controller;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cn.dnui_wnx725.dnuifood_16110100725.R;
import cn.dnui_wnx725.dnuifood_16110100725.bean.RegistBean;
import cn.dnui_wnx725.dnuifood_16110100725.listener.TListener;
import cn.dnui_wnx725.dnuifood_16110100725.model.UpdateModel;


public class UpdateInfoActivity extends BaseActivity {
    private TextView userid;
    private EditText username,userpass,usermobile,useraddress;
    private Button btn_submit,btn_cancel;
    private TListener<RegistBean> tListener = new TListener<RegistBean>() {
        @Override
        public void onResponse(RegistBean registBean) {
            if(registBean.getSuccess().equals("0")){
                showToast("修改失败");
            }else {
                showToast("修改成功");
                finish();
            }
        }

        @Override
        public void onFail(String msg) {

        }
    };


    @Override
    void initView() {
        setLayout_file(R.layout.activity_update_info);
        userid=findViewById(R.id.tv_userid);
        username=findViewById(R.id.et_username);
        userpass=findViewById(R.id.et_userpass);
        usermobile=findViewById(R.id.et_mobile);
        useraddress=findViewById(R.id.et_address);
        btn_submit=findViewById(R.id.btn_submit);
        btn_cancel=findViewById(R.id.btn_cancel);
//        userid.setText(getUserID());

    }

    @Override
    void initEvent() {
        btn_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String uname=username.getText().toString();
                String upass=userpass.getText().toString();
                String umobile=usermobile.getText().toString();
                String uaddress=useraddress.getText().toString();
                UpdateModel updateModel = new UpdateModel();
                if(uname.equals("")){
                    showToast("用户名为空!");
                }
                else if(upass.equals("")){
                    showToast("密码为空!");
                }
                else if(umobile.equals("")){
                    showToast("电话号为空!");
                }
                else if(uaddress.equals("")){
                    showToast("地址为空!");
                }
                else {
                    updateModel.getRegistMassage(getUserID(),uname,upass,umobile,uaddress,tListener);
                }
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initData() {
        userid.setText(getUserID());
    }


}
